package com.glsc.ngateway.common.api.platform.dto.it.networkassets;

import com.alibaba.excel.util.CollectionUtils;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;


/**
 * 第一张柱状图以【网络资产维护】表中vendor字段进行count数量统计，
 * 第二张柱状图，以【网络资产维护】表中status字段进行count数量统计，
 * 第三张柱状图以【网络资产维护】表中manufactureDate字段进行计算，与当前日期相差的年数<=3、>3且<=5、>5且<=6、>6四个维度来进行count数量统计
 *
 * @author xuchang
 */
@Data
@Builder
@ApiModel("网络资产DashBoard")
public class DashboardDto implements Serializable {
    private static final long serialVersionUID = 2524252359020702326L;
    @ApiModelProperty(value = "第一张柱状图以【网络资产维护】表中vendor字段进行count数量统计List<Map<String, Integer>>")
    DashboardDetailVo vendorGroup;
    @ApiModelProperty(value = "第二张柱状图，以【网络资产维护】表中status字段进行count数量统计List<Map<String, Integer>>")
    DashboardDetailVo statusGroup;
    @ApiModelProperty(value = "第三张柱状图以【网络资产维护】表中manufactureDate字段进行计算，与当前日期相差的年数<=3、>3且<=5、>5且<=6、>6四个维度来进行count数量统计Map<String, Integer>")
    DashboardDetailVo manufactureateDateGroup;

    /**
     * xAxis: {
     * data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
     * },
     * yAxis: {},
     * series: [
     * {
     * type: 'bar',
     * data: [23, 24, 18, 25, 27, 28, 25]
     * }
     * ]
     */
    @AllArgsConstructor
    @NoArgsConstructor
    @Data
    @Builder
    public static class DashboardDetailVo implements Serializable{
        private static final long serialVersionUID = 1399737706843666252L;
        //小写1个字母+大写必须用JsonProperty声明
        @JsonProperty("xAxis")
        XAxis xAxis;
        @JsonProperty("yAxis")
        YAxis yAxis;
        @Builder.Default
        @JsonProperty("series")
        List<Serie> series = java.util.Collections.EMPTY_LIST;

        public DashboardDetailVo(Map<String, Integer> map) {
            if(!CollectionUtils.isEmpty(map)){
                this.xAxis = new XAxis(new ArrayList<>(map.keySet()));
                this.yAxis = new YAxis();
                this.series = List.of(new Serie("bar", new ArrayList<>(map.values())));
            }
        }
    }

    /**
     * 横坐标
     */
    @AllArgsConstructor
    @NoArgsConstructor
    @Data
    @Builder
    public static class XAxis implements Serializable{
        private static final long serialVersionUID = -7850511391333006075L;
        List<String> data;
    }

    /**
     * 纵坐标
     */
    @AllArgsConstructor
    @NoArgsConstructor
    @Data
    @Builder
    public static class YAxis implements Serializable{
        private static final long serialVersionUID = -4561710101340589241L;
        String type;
    }

    /**
     * 数据
     */
    @AllArgsConstructor
    @NoArgsConstructor
    @Data
    @Builder
    public static class Serie implements Serializable{
        private static final long serialVersionUID = 3511756459241078440L;
        String type;
        List<Integer> data;
    }
}
